<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2008 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: register.php
| Author: Nick Jones (Digitanium)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "maincore.php";
require_once THEMES."templates/header.php";
include LOCALE.LOCALESET."register.php";
include LOCALE.LOCALESET."user_fields.php";

//Henter avloser id fra URL for å hente riktig kontrakter fra DB
$avloserid=$_GET['avloserid'];
//---------------------------------------------------------------------------------------------------------------------+
//------Funksjon for bekreftelse og sletting av kontrakt mot DB   (Hoppes over hvis ikke slettknappen er trykket)------+
//---------------------------------------------------------------------------------------------------------------------+
if(isset($_GET['slett']))

if(isset($_GET['confirm'])) {
	$sid=$_GET['sid'];
	$confirm=$_GET['confirm'];
	if ($_GET['confirm'] == "ja" )
		{
		$query1="DELETE FROM arbeidserfaring WHERE arbeidserf_id=$sid";
		mysql_query($query1);
		header("Refresh: 1; url=lagreerfaring.php?avloserid=".$_GET['avloserid']."&sjekk=nei");
		}
}
//---------------------------------------------------------------------------------------------------------------------+
//------------------------------------Slutt-på-funksjon-for-sletting-av-kontrakt---------------------------------------+
//---------------------------------------------------------------------------------------------------------------------+

//---------------------------------------------------------------------------------------------------------------------+
//----------Funksjon for lagring av kontrakt til DB     (Hoppes over hvis ikke lagreknappen er trykket)----------------+
//---------------------------------------------------------------------------------------------------------------------+
//Henter sjekk fra URL
$sjekk=$_GET['sjekk'];
if($sjekk=="ja") {
	$ud_arbeidssted=$_POST['ud_arbeidssted'];
	$ud_erfaring=$_POST['ud_erfaring'];
	$theDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
	$theDate2 = isset($_REQUEST["date2"]) ? $_REQUEST["date2"] : "";
	if($theDate > $theDate2)
		{
		echo" <h1 align='center'>Erfaringen kan ikke slutte f&oslash;r den har begynt!</h1>";
		}else if($theDate == $theDate2)
			{
			echo" <h1 align='center'>Erfaringen slutter samtidig som den starter!</h1>";
			}else {
				$db = mysql_connect($GLOBALS['db_host'], $GLOBALS['db_user'], $GLOBALS['db_password']);
				mysql_select_db($GLOBALS['db_name'], $db);  
				$query1="INSERT INTO arbeidserfaring VALUES ('',$avloserid,'$ud_arbeidssted','$ud_erfaring', '$theDate', '$theDate2')";
				mysql_query($query1);
				}
}	
//---------------------------------------------------------------------------------------------------------------------+
//------------------------------------Slutt-på-funksjon-for-lagring-av-kontrakt----------------------------------------+
//---------------------------------------------------------------------------------------------------------------------+


//---------------------------------------------------------------------------------------------------------------------+
//---------Kode for uthenting av erfaring-data fra DB og HTML printing til nettleser----(Utføres ved sidelasting)------+
//---------------------------------------------------------------------------------------------------------------------+
$query="SELECT  arbeidserf_id, fradato, tildato, arbeidssted, erfaring, arbeidserfaring.avloserid
		FROM arbeidserfaring, avloser
		WHERE arbeidserfaring.avloserid = avloser.avloserid
		AND arbeidserfaring.avloserid = $avloserid
		ORDER BY arbeidserfaring.tildato DESC;";
$result=mysql_query($query);
$num=mysql_numrows($result);

echo "<br></br>

	<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='profil.php?avloserid=$avloserid'><b><---  Tilbake til profil</b></a></p>
	<table class='capmain' border='0' cellpadding='0' align='center'>
		<tr>
			<th>Erfaring</th>
		</tr>
	</table>
	<table class='imagetable' border='0' cellpadding='5' align='center'>
		<tr>
			<th><b>Fradato</b></th>
			<th><b>Tildato</b></th>
			<th><b>Arbeidssted</b></th>
			<th><b>Erfaring</b></th>
			<th><b></b></th>
		</tr>
";
$i=0;
while ($i < $num) {
	$fra=mysql_result($result,$i,"fradato");
	$til=mysql_result($result,$i,"tildato");
	$asted=mysql_result($result,$i,"arbeidssted");
	$erfaring=mysql_result($result,$i,"erfaring");
	$sid=mysql_result($result,$i,"arbeidserf_id");
++$i;
echo "
	<form action='lagreerfaring.php?confirm=ja&sid=".$sid."&avloserid=".$avloserid."&slett=ja&sjekk=nei' onSubmit='return validateUpdate()' method='post'>
		<tr>
			<td>$fra</td>
			<td>$til</td>
			<td>$asted</td>
			<td>$erfaring</td>
			<td align=center><input type='submit' value='Slett' /></td>			
		</tr>
";
} //Slutt på While-løkke

echo "	</form></table><br></br>
		
		<form action='lagreerfaring.php?avloserid=".$avloserid."&sjekk=ja' method='post'>";
		require_once('calendar/classes/tc_calendar.php');
		  $myCalendar = new tc_calendar("date1", true);
		  $myCalendar->setIcon("calendar/images/iconCalendar.gif");
		  $myCalendar->setDate(01, 01, 2000);
		  $myCalendar->setPath("calendar/");
		  $myCalendar->setYearInterval(1940, 2030);
		  $myCalendar->dateAllow('1960-01-01', '2030-03-01');
		  $myCalendar2 = new tc_calendar("date2", true);
		  $myCalendar2->setIcon("calendar/images/iconCalendar.gif");
		  $myCalendar2->setDate(01, 01, 2000);
		  $myCalendar2->setPath("calendar/");
		  $myCalendar2->setYearInterval(1940, 2030);
		  $myCalendar2->dateAllow('1960-01-01', '2030-03-01');
	  
		echo" <table class='imagetable' border='1' cellpadding='5' align='center' >
			<tr>
				
				
				<td>";	$myCalendar->writeScript(); echo"  </td>		
				<td>";  $myCalendar2->writeScript(); echo"  </td>
				<td></td>
			</tr>
			<tr>	
				<td><input type='text' name='ud_arbeidssted' value='arbeidssted'></td>	
				<td><input type='text' name='ud_erfaring' value='Efaring'></td>	
				<td><input type='Submit' value='Legg til'></td>	
			</tr></form>
		</table><br></br>
";
//---------------------------------------------------------------------------------------------------------------------+
//----------Slutt på kode for uthenting av kontraktdata fra DB og HTML printing til nettleser--------------------------+
//---------------------------------------------------------------------------------------------------------------------+
require_once THEMES."templates/footer.php";
?>
<!-- JavaScript and HTML codes by Quackit.com -->
<script language="javascript" type="text/javascript" >
function validateUpdate(){
		var confirmLeave = confirm('Er du sikker?');
		return confirmLeave;
}
</script>

